package com.projectsquirrel;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import android.content.Context;
import android.content.SharedPreferences;



/* 
 * @Author Daniel
 * 
Day, "[DD]"
Month, "[MM]"
Year, "[YYYY]"
Hour, "[HH]"
Minute, "[MM]"
AMPM, "[XM]"
ZIP, "[XXXXX-XXXX]"
LATITUDE, "[example: 41.86962474217837]"
LONGITUDE, "[example: -87.6494836807251]"
EMAIL, "[XXX@XX.XXX]"
NUM_GRAY_SQUIRRELS, "[X]"
NUM_FOX_SQUIRRELS, "[X]"
SETTING, "[X, where X is one of: SINGLE_FAM, MULT_FAM, HIGHRISE, PARK, NATURE, GARDEN, COMMER, SCHOOL, LOT, CEMETERY, FARM]"
NUT_TREES, "[X, where X is one of: YES, NO, UNSURE]"
SEED_TREES, "[X, where X is one of: YES, NO, UNSURE]"
FRUIT_TREES, "[X, where X is one of: YES, NO, UNSURE]"
TINY_TREES, "[X, where X is one of: YES, NO, UNSURE]"
CON_TREES, "[X, where X is one of: YES, NO, UNSURE]"
OTHER_TREES, "[X, where X is a string]"
FEED_BIRD_FEEDER, "[X, where X is one of NEVER, SELDOM, OFTEN, REGULARLY]"
FEED_HANDOUTS, "[X, where X is one of NEVER, SELDOM, OFTEN, REGULARLY]"
FEED_GARBAGE, "[X, where X is one of NEVER, SELDOM, OFTEN, REGULARLY]"
FEED_TREES, "[X, where X is one of NEVER, SELDOM, OFTEN, REGULARLY]"
FEED_OTHER, "[X, where X is one of NEVER, SELDOM, OFTEN, REGULARLY]"
FEED_OTHER_DETAILS, "[X, where X is a string]"
NUM_SQUIRREL_CHANGE, "[X, where X is one of SAME, INCREASED, DECREASED]"
SITE_DOGS, "[X, where X is one of NONE, LOW, MEDIUM, HIGH]"
SITE_CATS, "[X, where X is one of NONE, LOW, MEDIUM, HIGH]"
SITE_COYOTES, "[X, where X is one of NONE, LOW, MEDIUM, HIGH]"
SITE_HAWKS, "[X, where X is one of NONE, LOW, MEDIUM, HIGH]"
SITE_GRAIN, "[X, where X is one of NONE, LOW, MEDIUM, HIGH]"
THIS_NEW_SITE, "[X, where X is one of YES, NO]"
USED_DIFFERENT_SITE, "[X, where X is one of YES, NO]"
COMMENTS, "[X, where X is a string]"
 */
public class Observation {
	//----Auto Generated----//
	private String name; //should be auto generated -ds
	private static Date createdDate = null;
	private int day; //assume to be error free
	private int month; //assume to be error free
	private int year; //assume to be error free
	private int minute; //assume to be error free
	private int hour; //assume to be error free
	private String amPm; //true if PM
	private String zip;
	private double latitude; 
	private double longitude;
	private String email; // auto-generated passed into constructor, we can assume it to be error free
	//----End Auto Generated----//
	
	//--screen1 method--
	private String numOfGraySquirrels;
	private String numOfFoxSquirrels;
	private String newSite;
	private String usedDifferentSite;
	private String numOfSqurChange;
	private String generalComments; // comment section
	//--end screen1 method--
	
	//--screen2 method--
	private String setting;
	private String nutTrees;
	private String seedTrees;
	private String fruitTrees;
	private String tinyTrees;
	private String conTrees;
	private String otherTreeComments; // comment section
	//--end screen2 method--
	
	//--screen3Feed method--
	private String feedFromBirdFeeder;
	private String feedFromHandouts;
	private String feedFromGarbage;
	private String feedFromTrees;
	private String feedFromOther;
	private String feedFromComments; // comment section
	//--end screen3Feed method--
	
	//--screen3Num method--
	private String numOfSiteDogs;
	private String numOfSiteCats;
	private String numOfSiteCoyotes;
	private String numOfSiteHawks;
	private String numOfSitePGrain;
	//--end screen3Num method--
	
	
	public Observation(String userEmail){
		Calendar calendar = new GregorianCalendar();
	    calendar.setTime(new Date());
	    createdDate = new Date();
		day = calendar.get(Calendar.DAY_OF_MONTH);
		month = calendar.get(Calendar.MONTH);
		year = calendar.get(Calendar.YEAR);
		minute = createdDate.getMinutes();
		hour = createdDate.getHours();
		
		
		if(hour>=12){
			amPm = "PM";
			hour -= 12;
		}
		else{
			amPm = "AM";
		}
		
		email = userEmail;
		name = createdDate.toString(); 
	}
public String getName(){
		return name;
	}
	public void setZip(String Zip){
		zip = Zip;
	}
	public String getDate(){
		return month+1+"-"+day+"-"+year;
	}
	public String getTime(){
		return pad(hour)+":"+pad(minute)+amPm;
	}
	public void setDate(int Day, int Month, int Year){
		day = Day;
		month = Month;
		year = Year;
	}
	public void setTime(int Hour, int Minute){
		if(Hour >=12){
			hour = Hour;
			hour-=12;
			amPm = "PM";
		}
		else{
			amPm = "AM";
		}
		
		minute = Minute;
	}
	public void setNumOfGray(String numOfGray){
		numOfGraySquirrels = numOfGray;
	}
	public void setLatLong(double lat, double Longitude){
		latitude = lat;
		longitude = Longitude;
	}
	public void setNumOfFox(String numOfFox){
		numOfFoxSquirrels = numOfFox;
	}
	public boolean setUsingSameSite(String new_Site){
		if(new_Site.equals("YES")||new_Site.equals("NO")){
			newSite = new_Site;
			return true;
		}
		return false;
	}
	public String getUsingSameSite(){
		return newSite;
	}
	public boolean setUsingDifSite(String usedDifSite){
		if(usedDifSite.equals("YES")||usedDifSite.equals("NO")){
			usedDifferentSite = usedDifSite;
			return true;
		}
		return false;
	}
	public boolean setNumOfSqurrelChange(String numOfSquirrelChange){
		if(numOfSquirrelChange.equals("SAME")||numOfSquirrelChange.equals("INCREASED")||numOfSquirrelChange.equals("DECREASED")){
			numOfSqurChange = numOfSquirrelChange;
			return true;
		}
		return false;
	}
	public void setGeneralComments(String comment){								
		generalComments = comment;
		
	}
	public void setSetting(String setting){
		this.setting = setting;
	}
 	private static String pad(int c) {
	        if (c >= 10)
	            return String.valueOf(c);
	        else
	            return "0" + String.valueOf(c);
	}
	/*
	 * @Arg Setting
	 * @Arg nutTrees
	 * @Arg seedTrees
	 * @Arg fruitTrees
	 * @Arg tinyTrees
	 * @Arg conTrees
	 * @Arg otherTreeComments
	 * This method takes the setting and all tree data,
	 * it validates all data based on the template provided by the TA, if the data is not valid it will return false.
	 * It is up to the caller to provide a notification to the user about invalid data.
	 * @Return true or false
	 * @Author Daniel
	 */
	public boolean screen2(String Setting, String nuttree, String seedtree, String fruittree, String tinytree, String contree, String treecomment){
		if(Setting.equals("SINGLE_FAM")
			||Setting.equals("MULT_FAM")
			||Setting.equals("HIGHRISE")
			||Setting.equals("PARK")
			||Setting.equals("NATURE")
			||Setting.equals("GARDEN")
			||Setting.equals("COMMER")
			||Setting.equals("SCHOOL")
			||Setting.equals("LOT")
			||Setting.equals("CEMETERY")
			||Setting.equals("FARM"))
		{
			// setting must be: SINGLE_FAM, MULT_FAM, HIGHRISE, PARK, NATURE, GARDEN, COMMER, SCHOOL, LOT, CEMETERY, FARM
			if(nuttree.equals("YES")||nuttree.equals("NO")||nuttree.equals("UNSURE")){
				if(seedtree.equals("YES")||seedtree.equals("NO")||seedtree.equals("UNSURE")){
					if(fruittree.equals("YES")||fruittree.equals("NO")||fruittree.equals("UNSURE")){
						if(tinytree.equals("YES")||tinytree.equals("NO")||tinytree.equals("UNSURE")){
							if(contree.equals("YES")||contree.equals("NO")||contree.equals("UNSURE")){
								setting = Setting;
								nutTrees = nuttree;
								seedTrees = seedtree;
								fruitTrees = fruittree;
								tinyTrees = tinytree;
								conTrees = contree;
								otherTreeComments = treecomment;
								return true;
							}
						}						
					}					
				}			
			}
		}
		return false;			
	}	
	/*
	 * @Arg fromBirdFeeder
	 * @Arg fromHandouts
	 * @Arg fromGarbage
	 * @Arg fromTrees
	 * @Arg fromOther
	 * @Arg fromOtherComment
	 * This method takes all food data,
	 * it validates all data based on the template provided by the TA, if the data is not valid it will return false.
	 * It is up to the caller to provide a notification to the user about invalid data.
	 * @Return true or false
	 * @Author Daniel
	 */	
public boolean screen3Feed(String fromBirdFeeder, String fromHandouts, String fromGarbage, String fromTrees, String fromOther, String fromOtherComment){
		//must be one of: NEVER, SELDOM, OFTEN, REGULARLY
		if(fromBirdFeeder.equals("NEVER")||fromBirdFeeder.equals("SELDOM")||fromBirdFeeder.equals("OFTEN")||fromBirdFeeder.equals("REGULARLY")){
			if(fromHandouts.equals("NEVER")||fromHandouts.equals("SELDOM")||fromHandouts.equals("OFTEN")||fromHandouts.equals("REGULARLY")){
				if(fromGarbage.equals("NEVER")||fromGarbage.equals("SELDOM")||fromGarbage.equals("OFTEN")||fromGarbage.equals("REGULARLY")){
					if(fromTrees.equals("NEVER")||fromTrees.equals("SELDOM")||fromTrees.equals("OFTEN")||fromTrees.equals("REGULARLY")){
						if(fromOther.equals("NEVER")||fromOther.equals("SELDOM")||fromOther.equals("OFTEN")||fromOther.equals("REGULARLY")){
							feedFromBirdFeeder = fromBirdFeeder;
							feedFromHandouts = fromHandouts;
							feedFromGarbage = fromGarbage;
							feedFromTrees = fromTrees;
							feedFromOther = fromOther;
							feedFromComments = fromOtherComment;
							return true;
						}
					}
				}
			}
		}
		return false;
	}
	/*
	 * @Arg numOfDogs
	 * @Arg numOfCats
	 * @Arg numOfCoyotes
	 * @Arg numOfHawks
	 * @Arg fromOther
	 * This method takes all predator data,
	 * it validates all data based on the template provided by the TA, if the data is not valid it will return false.
	 * It is up to the caller to provide a notification to the user about invalid data.
	 * @Return true or false
	 * @Author Daniel
	 */
	public boolean screen3Num(String numOfDogs, String numOfCats, String numOfCoyotes, String numOfHawks, String numOfPGrain){
		//must be one of: NONE, LOW, MEDIUM, HIGH
		if(numOfDogs.equals("NONE")||numOfDogs.equals("LOW")||numOfDogs.equals("MEDIUM")||numOfDogs.equals("HIGH")){
			if(numOfCats.equals("NONE")||numOfCats.equals("LOW")||numOfCats.equals("MEDIUM")||numOfCats.equals("HIGH")){
				if(numOfCoyotes.equalsIgnoreCase("NONE")||numOfCoyotes.equalsIgnoreCase("LOW")||numOfCoyotes.equalsIgnoreCase("MEDIUM")||numOfCoyotes.equalsIgnoreCase("HIGH")){
					if(numOfHawks.equals("NONE")||numOfHawks.equals("LOW")||numOfHawks.equals("MEDIUM")||numOfHawks.equals("HIGH")){
						if(numOfPGrain.equals("NONE")||numOfPGrain.equals("LOW")||numOfPGrain.equals("MEDIUM")||numOfPGrain.equals("HIGH")){
							numOfSiteDogs = numOfDogs;
							numOfSiteCats = numOfCats;
							numOfSiteCoyotes = numOfCoyotes;
							numOfSiteHawks = numOfHawks;
							numOfSitePGrain = numOfPGrain;
							return true;
						}
					}
				}
			}
		}
		return false;
	}
	
	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 * 
	 * This lovely method converts all class data into a string which can be directly ported to an output file
	 * This format was based upon the TA's guidelines.
	 * @Author Daniel
	 */
	public String toString(){
		String ret = 
			"Day, ["+day+"]\n"
			+"Month, ["+(month+1)+"]\n"
			+"Year, ["+year+"]\n"
			+"Hours, ["+hour+"]\n"
			+"Minute, ["+minute+"]\n"
			+"AMPM, ["+amPm+"]\n"
			+"ZIP, ["+zip+"]\n"
			+"LATITUDE, ["+latitude+"]\n"
			+"LONGITUDE, ["+longitude+"]\n"
			+"EMAIL, ["+email+"]\n"
			+"NUM_GRAY_SQUIRRELS, ["+numOfGraySquirrels+"]\n"
			+"NUM_FOX_SQUIRRELS, ["+numOfFoxSquirrels+"]\n"
			+"SETTING, ["+setting+"]\n"
			+"NUT_TREES, ["+nutTrees+"]\n"
			+"SEED_TREES, ["+seedTrees+"]\n"
			+"FRUIT_TREES, ["+fruitTrees+"]\n"
			+"TINY_TREES, ["+tinyTrees+"]\n"
			+"CON_TREES, ["+conTrees+"]\n"
			+"OTHER_TREES, ["+otherTreeComments+"]\n"
			+"FEED_BIRD_FEEDER, ["+feedFromBirdFeeder+"]\n"
			+"FEED_HANDOUTS, ["+feedFromHandouts+"]\n"
			+"FEED_GARBAGE, ["+feedFromGarbage+"]\n"
			+"FEED_TREES, ["+feedFromTrees+"]\n"
			+"FEED_OTHER, ["+feedFromOther+"]\n"
			+"FEED_OTHER_DETAILS, ["+feedFromComments+"]\n"
			+"NUM_SQUIRREL_CHANGE, ["+numOfSqurChange+"]\n"
			+"SITE_DOGS, ["+numOfSiteDogs+"]\n"
			+"SITE_CATS, ["+numOfSiteCats+"]\n"
			+"SITE_COYOTES, ["+numOfSiteCoyotes+"]\n"
			+"SITE_HAWKS, ["+numOfSiteHawks+"]\n"
			+"SITE_GRAIN, ["+numOfSitePGrain+"]\n"
			+"THIS_NEW_SITE, ["+newSite+"]\n"
			+"USED_DIFFERENT_SITE, ["+usedDifferentSite+"]\n"
			+"COMMENTS, ["+generalComments+"]\n";
		return ret;
	}
	public void setNutTree(String text) {
		nutTrees = text;
	}
	public void setSeedTree(String text) {
		seedTrees = text;
	}

	/*
	 * Read From File to populate an observation:
	 * int i = 0;
		
		while(!fileNames[i].equals(null)){
			FileInputStream fileStream = new FileInputStream(fileNames[i]);
			openFileInput(fileNames[i]);
			i++;
		}
		public void readFromFile(String filename){
		try {
			FileOutputStream fos = openFileOutput(filename, Context.MODE_PRIVATE);
			fos.write(string.getBytes());
			fos.close();
		} 
		catch (java.io.FileNotFoundException e) {
		    // do something if the myfilename.txt does not exits
		  }
	}
	 * 
	 */
}
